package com.example.barcodeapp.ui.wode.fragment;


import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.barcodeapp.R;
import com.example.barcodeapp.base.BaseFragment;
import com.example.barcodeapp.interfaces.IBasePersenter;
import com.example.barcodeapp.interfaces.own.IOwn;
import com.example.barcodeapp.persenter.own.WoDeJiFenListPresenter;
import com.example.barcodeapp.ui.wode.adapter.OkAdapter1;
import com.example.barcodeapp.ui.wode.adapter.OkAdapter2;
import com.example.barcodeapp.ui.wode.bean.JiFenListBean;
import com.example.barcodeapp.ui.wode.bean.Score;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class UseFragment extends BaseFragment<IOwn.JiFenListPresenter> implements IOwn.JiFenListView {
    @BindView(R.id.ok)
    RecyclerView ok;
    private ArrayList<Score> list;

    @Override
    protected int getLayout() {
        return R.layout.use_fragment;
    }


    @Override
    protected void initView() {
        ok.setLayoutManager(new LinearLayoutManager(getActivity()));
        list = new ArrayList<>();
    }

    @Override
    protected WoDeJiFenListPresenter initPersenter() {
        return new WoDeJiFenListPresenter();
    }

    @Override
    protected void initData() {
        persenter.getJiFenList(2, 1, "xiaohao");
    }

    @Override
    public void getJiFenListBean(JiFenListBean jiFenListBean) {
        List<JiFenListBean.DataBean> data = jiFenListBean.getData();
        for (int i = 0; i < data.size(); i++) {
            String addtime = data.get(i).getAddtime();
            Integer jifenNum = data.get(i).getJifenNum();
            String num = String.valueOf(jifenNum);
            String type = data.get(i).getType();
            Score score = new Score(type, addtime, num);
            list.add(score);
        }
        if (list != null && list.size() > 0) {
            OkAdapter2 okAdapter = new OkAdapter2(getActivity(), list);
            ok.setAdapter(okAdapter);
            okAdapter.notifyDataSetChanged();
        }
    }
}
